import os
import shutil

def find_bzm_files(directory):
    bzm_files = []
    for root, _, files in os.walk(directory):
        for file in files:
            if file.endswith('.bzm'):
                bzm_files.append(os.path.join(root, file))
    return bzm_files

def create_java_files(bzm_files):
    java_files = []
    for bzm_file in bzm_files:
        java_file = bzm_file.replace('.bzm', '.java')
        java_files.append(java_file)        
    return java_files

def copy_content_to_bzm(java_files, bzm_files):
    for java_file, bzm_file in zip(java_files, bzm_files):
        try:
            shutil.copyfile( bzm_file,java_file)
        except:
            print(f"Failed to copy {java_file} to {bzm_file}")


def main(directory):
    bzm_files = find_bzm_files(directory)
    java_files = create_java_files(bzm_files)
    copy_content_to_bzm(java_files, bzm_files)
    print(f"Processed {len(bzm_files)} .bzm files")

if __name__ == "__main__":
    directory = r"E:/04robot/robot-hop/"  # 替换为你的文件夹路径
    main(directory)
